package com.user.controller;


import com.ruoyi.common.core.domain.R;
import com.user.entity.AdminMenu;
import com.user.service.AdminMenuService;
import com.user.service.AdminUserService;
import domain.AdminUser;
import model.LoginUser;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;
import java.util.Set;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author rick
 * @since 2022-12-13 11:23:15
 */
@RestController
@RequestMapping("/rick/user")
public class AdminUserController {
    @Autowired
    private AdminUserService adminUserService;
    @Autowired
    AdminMenuService adminMenuService;

    @RequestMapping("/adminuser")
    public R<LoginUser> getUser(@RequestBody String username) {
        System.out.println("远程调用了");
        AdminUser sysUser = adminUserService.getAdminUser(username);
        if (Objects.isNull(sysUser)) {
            return R.fail("抱歉，没有找到该用户");
        }
        Set<String> menusSet = adminMenuService.getAdminMenuItems(sysUser.getUserId());
        LoginUser sysUserVo = new LoginUser();
        sysUserVo.setAdminUser(sysUser);
        sysUserVo.setRoles(menusSet);
        return R.ok(sysUserVo);
    }

}
